package net.csdn.business.notify.api.config;


import net.csdn.business.notify.api.action.*;
import net.csdn.business.notify.common.enums.ProcessTypeEnum;
import net.csdn.business.notify.common.pipeline.ProcessController;
import net.csdn.business.notify.common.pipeline.ProcessTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName PipelineConfig
 * @Description 执行链路配置
 * @Author zhangyl
 * @Date 2023/11/29 16:28
 */
@Configuration
public class PipelineConfig {

    @Autowired
    private RemindPreCheckAction remindPreCheckAction;
    @Autowired
    private RemindAssembleAction remindAssembleAction;
    @Autowired
    private SendRemindMqAction sendRemindMqAction;


    /**
     * 普通发送执行流程
     * 1. 前置参数校验
     * 2. 根据模板组装参数
     * 3. 发送消息至MQ
     *
     * @return
     */
    @Bean("SendNotifyTemplate")
    public ProcessTemplate sendNotifyTemplate() {
        ProcessTemplate processTemplate = new ProcessTemplate();
        processTemplate.setProcessList(Arrays.asList(remindPreCheckAction, remindAssembleAction, sendRemindMqAction));
        return processTemplate;
    }



    @Autowired
    private DirectPreCheckAction directPreCheckAction;
    @Autowired
    private DirectAssembleAction directAssembleAction;
    @Autowired
    private SendDirectMqAction sendDirectMqAction;


    /**
     * 直接根据账号发送营销类通知执行流程
     * 1. 前置参数校验
     * 2. 根据模板组装参数
     * 3. 发送消息至MQ
     *
     * @return
     */
    @Bean("SendDirectTemplate")
    public ProcessTemplate sendDirectTemplate() {
        ProcessTemplate processTemplate = new ProcessTemplate();
        processTemplate.setProcessList(Arrays.asList(directPreCheckAction, directAssembleAction, sendDirectMqAction));
        return processTemplate;
    }


    @Autowired
    private PrivatePreCheckAction privatePreCheckAction;
    @Autowired
    private SendPrivateMqAction sendUserPrivateMqAction;

    /**
     * 发送用户私信执行流程
     * 1. 前置参数校验,已经预处理私信参数
     * 2. 发送消息至MQ
     *
     * @return
     */
    @Bean("SendPrivateTemplate")
    public ProcessTemplate sendPrivateTemplate() {
        ProcessTemplate processTemplate = new ProcessTemplate();
        processTemplate.setProcessList(Arrays.asList(privatePreCheckAction, sendUserPrivateMqAction));
        return processTemplate;
    }


    /**
     * pipeline流程控制器
     * 后续扩展则加BusinessCode和ProcessTemplate
     *
     * @return
     */
    @Bean("apiProcessController")
    public ProcessController apiProcessController() {
        ProcessController processController = new ProcessController();
        Map<String, ProcessTemplate> templateConfig = new HashMap<>(10);
        templateConfig.put(ProcessTypeEnum.SEND_REMIND_NOTIFY.getCode(), sendNotifyTemplate());
        templateConfig.put(ProcessTypeEnum.SEND_DIRECT_NOTIFY.getCode(), sendDirectTemplate());
        templateConfig.put(ProcessTypeEnum.SEND_PRIVATE_NOTIFY.getCode(), sendPrivateTemplate());
        processController.setTemplateConfig(templateConfig);
        return processController;
    }

}
